package com.px.scserver.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.px.sccommon.util.SecurityUtil;
import com.px.scserver.api.pc.v1.request.FeedbackPageRequest;
import com.px.scserver.api.pc.v1.request.SolveFeedBackRequest;
import com.px.scserver.api.wx.v1.request.FeedbackAddRequest;
import com.px.scserver.api.wx.v1.vo.FeedbackVO;
import com.px.scserver.po.Feedback;
import com.px.scserver.service.FeedbackService;
import com.px.scserver.mapper.FeedbackMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

/**
 * @author 品讯科技
 * @description 针对表【sc_feedback】的数据库操作Service实现
 * @createDate 2023-09-14 22:14:29
 */
@Slf4j
@AllArgsConstructor
@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements FeedbackService {

    @Override
    public void create(FeedbackAddRequest request) {
        Feedback feedback = new Feedback();
        feedback.setUserId(SecurityUtil.getUserId());
        feedback.setContent(request.getContent());
        if (CollectionUtils.isNotEmpty(request.getImgList())) {
            feedback.setImgList(request.getImgList().toArray(String[]::new));
        }
        save(feedback);
    }

    @Override
    public IPage<FeedbackVO> pcPage(FeedbackPageRequest request) {

        return getBaseMapper().pcPage(new Page<>(request.getCurrent(), request.getSize()), request);
    }

    @Override
    public void solve(SolveFeedBackRequest request) {
        Feedback feedback = new Feedback();
        feedback.setId(request.getId());
        feedback.setSolve(request.getSolve());
        feedback.setResult(request.getResult());
        feedback.setResultImgList(request.getResultImgList().toArray(String[]::new));
        updateById(feedback);
    }
}




